//
//  UnderstandViewController.m
//  WheatPlan
//
//  Created by 王晨辉 on 15/5/27.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.
//

#import "UnderstandViewController.h"
#import "UIImageView+WebCache.h"

@interface UnderstandViewController (){
    
    NSMutableArray *_provinceArray;

    
}

@end

@implementation UnderstandViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置导航栏头文字
    self.navigationItem.title = @"了解上门早教";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#ef5858" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
                      forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back)
     forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 15);
    
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.leftBarButtonItem = menuButton;
    
    self.view.backgroundColor = [UIColor  whiteColor];
    
//    [GetFileModel ShowProgressHUDwithMessage:@"耐心等待"];
    [self subView];


}
-(void)back{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

-(void)subView{
    
    int a =  self.navigationController.navigationBar.frame.size.height+20;
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    
    NSString *ID = [user objectForKey:@"ID"];
    NSDictionary *param = @{@"userId": ID,@"contentId":@"1",@"ealyType":@"2"};
    [UserDAL getPreschoolEducationInfoParamsTwo:param withBlock:^(NSDictionary *data, NSError *error) {
        
        
        ////NSLog(@"%@222223333333444444",data);
        
        if (data == 0) {
            
//            [JKAlert showMessage:@"提示" message:@"暂无可了解事项"];
            alert(@"暂无可了解事项");
            
            
        } else {
            NSString * imageviewStr = [data objectForKey:@"imageUrl"];/*@"http://c.hiphotos.baidu.com/image/pic/item/359b033b5bb5c9ea4fb6cdead739b6003af3b376.jpg"*/;
            NSString * contentStr = [data objectForKey:@"content"];
            NSString * msgStr = [data objectForKey:@"msg"];
            ////NSLog(@"%@%@%@",imageviewStr,contentStr,msgStr);
            
            UIImageView * UnderstandView = [[UIImageView alloc]initWithFrame:CGRectMake(0, a, SCREEN_WIDTH, 128)];
            //            UnderstandView.image = [UIImage imageNamed:@"huodong.png"];
            
            // set the image directly
            /**
             1. download
             2. get the image size
             3. compress/scale it
             4. fit size with your imageview size
             */
            
            //图片自适应宽高
//            [UnderstandView setContentMode:UIViewContentModeScaleAspectFit];
            
            [UnderstandView sd_setImageWithURL:[NSURL  URLWithString:imageviewStr] placeholderImage:nil];
            
            

            //    UnderstandView.backgroundColor = [UIColor redColor];
            [self.view addSubview:UnderstandView];
            
            
            UIView *lineView1 = [[UIView alloc]initWithFrame:CGRectMake(0,a+137, SCREEN_WIDTH, 1)];
            lineView1.backgroundColor = UIColorWithRGBA(187, 187, 187, 1);
            [self.view addSubview:lineView1];
            
            UIView *lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0,a+128, SCREEN_WIDTH, 11)];
            lineView2.backgroundColor = UIColorWithRGBA(240, 239, 245, 1);
            [self.view addSubview:lineView2];
            
            
            scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, a+138, SCREEN_WIDTH, 460)];
            scrollView.delegate = self;
            [scrollView flashScrollIndicators];
            scrollView.directionalLockEnabled = YES;
            
            UILabel * longLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, SCREEN_WIDTH, 30)];
            longLab.text = @"课程";
            //            longLab.text = contentStr;
            longLab.font = [UIFont systemFontOfSize:20];
            longLab.textAlignment = NSTextAlignmentCenter;
            
            UILabel * testlable = [[UILabel alloc]initWithFrame:CGRectMake(15,35,200,20)];
            NSString * tstring =contentStr;
            testlable.numberOfLines =0;
            UIFont * tfont = [UIFont systemFontOfSize:11];
            testlable.font = tfont;
            testlable.lineBreakMode =NSLineBreakByTruncatingTail ;
            testlable.text = tstring ;
            [testlable setBackgroundColor:[UIColor whiteColor]];
            [self.view addSubview:testlable];
            //高度估计文本大概要显示几行，宽度根据需求自己定义。 MAXFLOAT 可以算出具体要多高
            CGSize size =CGSizeMake(SCREEN_WIDTH-30,MAXFLOAT);
            // label可设置的最大高度和宽度
            //    CGSize size = CGSizeMake(300.f, MAXFLOAT);
            //    获取当前文本的属性
            NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
            //ios7方法，获取文本需要的size，限制宽度
            CGSize  actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
            testlable.frame =CGRectMake(15,35, actualsize.width, actualsize.height);
            
            
            
            [scrollView addSubview:testlable];
            [scrollView addSubview:longLab];
            [self.view addSubview:scrollView];
            

        }
        
    }];
    

}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{
    NSString *msg = [[NSString alloc] initWithFormat:@"您点击的是第%d个按钮!",buttonIndex];
    ////NSLog(@"msg:%@",msg);
    if (buttonIndex == 0) {
        
        [self dismissViewControllerAnimated:YES completion:nil];
        ////NSLog(@"1111111");
        
    }else if(buttonIndex == 1){
        
        
        ////NSLog(@"2222222");
        
        
    }
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
